package com.example.luke.cashorderingsystem.Database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Path;


import com.example.luke.cashorderingsystem.Model.Good;
import com.example.luke.cashorderingsystem.Model.GoodType;
import com.example.luke.cashorderingsystem.Model.Operator;
import com.example.luke.cashorderingsystem.Model.PurchaseReport;
import com.example.luke.cashorderingsystem.Util.GlobalFunction;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

/**
 * Created by luke on 9/21/16.
 */
public class DingHanDB extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "DingHan.db";

   private static final int DATABASE_VERSION = 1;
  private static DingHanDB dingHanDB=null;



    public static DingHanDB getInstance(Context context){
        if (dingHanDB==null)
            dingHanDB=new DingHanDB(context);

        return dingHanDB;

    }
   public DingHanDB(Context context){

      super(context,DATABASE_NAME,null,DATABASE_VERSION);


  }

    @Override
    public void onCreate(SQLiteDatabase db) {
         db.execSQL(Good.DH_CREATE_TABLE);
         db.execSQL(GoodType.DH_CREATE_TABLE);
        db.execSQL(PurchaseReport.DH_CREATE_TABLE);
        db.execSQL(Operator.DH_CREATE_TABLE);
      //  db.execSQL(DH_CREATE_TABLE);
//        db.execSQL(PurchasedItemTB.DH_CREATE_TABLE);
//        db.execSQL(RefundGoodTB.DH_CREATE_TABLE);
//        db.execSQL(MenuItemTB.DH_CREATE_TABLE);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + Good.DH_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + GoodType.DH_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + PurchaseReport.DH_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + Operator.DH_TABLE_NAME);
//        db.execSQL("DROP TABLE IF EXISTS " + PurchasedItemTB.DH_TABLE_NAME);
//        db.execSQL("DROP TABLE IF EXISTS " + RefundGoodTB.DH_TABLE_NAME);
//        db.execSQL("DROP TABLE IF EXISTS " + MenuItemTB.DH_TABLE_NAME);

        onCreate(db);


    }

  private ContentValues contentValuesFromObj(Object object){
        ContentValues contentValues=new ContentValues();
//
        if (object.getClass()== Good.class){

            Good record=(Good) object;
            contentValues.put(Good.item_barcode,record.getBarcode());
            contentValues.put(Good.item_discountable,record.getDisoountable());
            contentValues.put(Good.item_id,record.getId());
            contentValues.put(Good.item_kind,record.getKind());
            contentValues.put(Good.item_name,record.getName());
            contentValues.put(Good.item_pinyinID,record.getPinyinID());
            contentValues.put(Good.item_priceout,record.getPriceOut());
            contentValues.put(Good.item_priceIn,record.getPriceIn());
            contentValues.put(Good.item_warning,record.getWarning());
            contentValues.put(Good.item_storedNumber,record.getStoredNumber());



        }else if(object.getClass()==GoodType.class){
            GoodType record=(GoodType) object;
            contentValues.put(GoodType.item_id,record.getId());
            contentValues.put(GoodType.item_name,record.getName());

        }else if (object.getClass()== PurchaseReport.class){

            PurchaseReport record=(PurchaseReport) object;
            contentValues.put(PurchaseReport.item_ticketID,record.getTicketID());
            contentValues.put(PurchaseReport.item_commodityID,record.getCommodityID());
            contentValues.put(PurchaseReport.item_commodityName,record.getCommodityName());
            contentValues.put(PurchaseReport.item_volume,record.getVolume());
            contentValues.put(PurchaseReport.item_primeCost,record.getPrimeCost());
            contentValues.put(PurchaseReport.item_saleCost,record.getSaleCost());
            contentValues.put(PurchaseReport.item_cost,record.getCost());
            contentValues.put(PurchaseReport.item_restoredNum,record.getRestoredNum());
            contentValues.put(PurchaseReport.item_discount,record.getDisCount());
            contentValues.put(PurchaseReport.item_dateTime,record.getDateTime());
            contentValues.put(PurchaseReport.item_dateTimeCopy,record.getDateTimeCopy());
            contentValues.put(PurchaseReport.item_employeeID,record.getEmployeeID());
            contentValues.put(PurchaseReport.item_payMode,record.getPayMode());
            contentValues.put(PurchaseReport.item_uploadMark,record.getUploadMark());


        }else if(object.getClass()==Operator.class){

            Operator operator=(Operator)object;
            contentValues.put(Operator.operator_operCardNo,operator.getOperCardNo());
            contentValues.put(Operator.operator_employeeID,operator.getEmployeeID());
            contentValues.put(Operator.operator_password,operator.getPassword());
            contentValues.put(Operator.operator_authority,operator.getAuthority());

        }



        return contentValues;

    }
    public void insert(String tableName, Object object){

        try {

            SQLiteDatabase db=this.getWritableDatabase();

            db.insert(tableName, null, contentValuesFromObj(object));

            db.close();


        }catch (Exception e){



      GlobalFunction.printTextByTag(e.getMessage());

        }

    }
    public ArrayList<GoodType> getGoodTypeList(){
                SQLiteDatabase db=this.getReadableDatabase();

        Cursor res=db.rawQuery("Select * from "+GoodType.DH_TABLE_NAME,null);
        ArrayList <GoodType> temp=new ArrayList<>();


        if (res.moveToFirst()){
            GlobalFunction.printTextByTag("q succ");
            while (!res.isAfterLast()){

                GoodType goodType=new GoodType(res.getString(res.getColumnIndex(GoodType.item_id))
                        ,res.getString(res.getColumnIndex(GoodType.item_name)));
                temp.add(goodType);

                res.moveToNext();

            }


        }else {
            GlobalFunction.printTextByTag("q fail");
        }
        return temp;


    }

    public ArrayList<Good> getGoodDetailList(){
        SQLiteDatabase db=this.getReadableDatabase();

        Cursor res=db.rawQuery("Select * from "+Good.DH_TABLE_NAME,null);
        ArrayList <Good> temp=new ArrayList<>();


        if (res.moveToFirst()){
            GlobalFunction.printTextByTag("q succ");
            while (!res.isAfterLast()){

                Good good=new Good();
                good.setId(res.getString(res.getColumnIndex(Good.item_id)));
                good.setName(res.getString(res.getColumnIndex(Good.item_name)));
                good.setStoredNumber(res.getString(res.getColumnIndex(Good.item_storedNumber)));
                good.setPriceOut(res.getString(res.getColumnIndex(Good.item_priceout)));
                good.setPinyinID(res.getString(res.getColumnIndex(Good.item_pinyinID)));
                good.setKind(res.getString(res.getColumnIndex(Good.item_kind)));
                good.setPriceIn(res.getString(res.getColumnIndex(Good.item_priceIn)));
               // good.setId(res.getString(res.getColumnIndex(Good.item_id)));
            good.setDisoountable(res.getString(res.getColumnIndex(Good.item_discountable)));
                temp.add(good);

                res.moveToNext();

            }


        }else {
            GlobalFunction.printTextByTag("q fail");
        }
        return temp;


    }

    public ArrayList<PurchaseReport> getPurchaseReport(){
        SQLiteDatabase db=this.getReadableDatabase();

        Cursor res=db.rawQuery("Select * from "+PurchaseReport.DH_TABLE_NAME + " WHERE " + PurchaseReport.item_employeeID + "="+Operator.getIntance().getEmployeeID(),null);
        ArrayList <PurchaseReport> temp=new ArrayList<>();


        if (res.moveToFirst()){
            GlobalFunction.printTextByTag("q succ");
            while (!res.isAfterLast()){
                 PurchaseReport report=new PurchaseReport();
                report.setTicketID(res.getString(res.getColumnIndex(PurchaseReport.item_ticketID)));
                report.setCommodityID(res.getString(res.getColumnIndex(PurchaseReport.item_commodityID)));
                report.setVolume(res.getInt(res.getColumnIndex(PurchaseReport.item_volume)));
                report.setPrimeCost(res.getString(res.getColumnIndex(PurchaseReport.item_primeCost)));
                report.setSaleCost(res.getString(res.getColumnIndex(PurchaseReport.item_saleCost)));
                report.setCost(res.getString(res.getColumnIndex(PurchaseReport.item_cost)));
                report.setRestoredNum(res.getInt(res.getColumnIndex(PurchaseReport.item_restoredNum)));
                report.setDisCount(res.getString(res.getColumnIndex(PurchaseReport.item_discount)));
                report.setDateTime(res.getString(res.getColumnIndex(PurchaseReport.item_dateTime)));
                report.setDateTimeCopy(res.getString(res.getColumnIndex(PurchaseReport.item_dateTimeCopy)));
                report.setEmployeeID(res.getString(res.getColumnIndex(PurchaseReport.item_employeeID)));
                report.setCommodityName(res.getString(res.getColumnIndex(PurchaseReport.item_commodityName)));
                report.setUploadMark(res.getInt(res.getColumnIndex(PurchaseReport.item_uploadMark)));

//                GoodType goodType=new GoodType(res.getString(res.getColumnIndex(GoodType.item_id))
//                        ,res.getString(res.getColumnIndex(GoodType.item_name)));
                temp.add(report);
//
                res.moveToNext();

            }

           res.close();
        }else {
            GlobalFunction.printTextByTag("q fail");
        }

        return temp;


    }


    public   void removeAllGood(){
        SQLiteDatabase db=this.getReadableDatabase();


        String query="DELETE FROM "+Good.DH_TABLE_NAME;


        db.execSQL(query);
        db.close();

    }

    public   void removeAllGoodType(){
        SQLiteDatabase db=this.getReadableDatabase();


        String query="DELETE FROM "+GoodType.DH_TABLE_NAME;


        db.execSQL(query);
        db.close();

    }

     public   void updateGoodStoredNum(Good good){
         SQLiteDatabase db=this.getReadableDatabase();


       String query="UPDATE "+good.DH_TABLE_NAME+ " SET "+ good.item_storedNumber + "="+good.getStoredNumber()+
            " WHERE "+good.item_id+"="+good.getId();

       db.execSQL(query);
       db.close();

    }

    public   void changeReportUploadMark(PurchaseReport report){
        SQLiteDatabase db=this.getReadableDatabase();


        String query="UPDATE "+PurchaseReport.DH_TABLE_NAME+ " SET "+ PurchaseReport.item_uploadMark + "="+report.getUploadMark()+
                " WHERE "+ PurchaseReport.item_ticketID+"="+report.getTicketID()+" AND "+ PurchaseReport.item_commodityID+"="+report.getCommodityID();


        db.execSQL(query);
        db.close();

    }


    public ArrayList<Operator> getOperatorList(){
        SQLiteDatabase db=this.getReadableDatabase();

        Cursor res=db.rawQuery("Select * from "+Operator.DH_TABLE_NAME,null);
        ArrayList <Operator> temp=new ArrayList<>();


        if (res.moveToFirst()){
            GlobalFunction.printTextByTag("q succ");
            while (!res.isAfterLast()){
                Operator operator=new Operator(res);


                temp.add(operator);
//
                res.moveToNext();

            }

            res.close();

        }else {

            GlobalFunction.printTextByTag("q fail");
        }

        return temp;


    }


//    public CardRecord getCorresPondReport(PurchasedItemTB.Item purchaseItem){
//        CardRecord record=null;
//        SQLiteDatabase db=this.getReadableDatabase();
//
//        Cursor res=db.query(DH_TABLE_NAME,null,  DH_Card_No + " = ?" +" AND "+DH_Card_TicketID+" = ?",
//                new String[]{purchaseItem.card_ID,purchaseItem.item_TicketID},null,null,null);
//
//        if (res.moveToFirst()){
//            record  =new CardRecord(res.getString(res.getColumnIndex(DH_Card_No)))  ;
//
//            record.UsageCount=res.getInt(res.getColumnIndex(DH_Card_UsageCount));
//            record.PurchaseAmount=res.getInt(res.getColumnIndex(DH_Card_purchaseAmount));
//            record.Remain=res.getInt(res.getColumnIndex(DH_Card_remain));
//            record.DiscountRate=res.getString(res.getColumnIndex(DH_Card_discountRate));
//            record.usageDate=res.getString(res.getColumnIndex(DH_Card_Date));
//            record.DeviceNo=res.getString(res.getColumnIndex(DH_Card_DeviceNo));
//            record.Operator=res.getString(res.getColumnIndexOrThrow(DH_Card_Operator));
//            record.ReportType=res.getInt(res.getColumnIndex(DH_Card_ReportType));
//            record.refundIndex=res.getInt(res.getColumnIndex(DH_Card_RefundIndex));
//
//
//            // GlobalFunction.printTextByTag("search success");
//
//        }else {
//
//            GlobalFunction.printTextByTag("search fail");
//        }
//        res.close();
//
//
//        return record;
//
//    }
//


//    public void insertRecord(CardRecord record){
//
//        SQLiteDatabase db=this.getWritableDatabase();
//        ContentValues contentValues=new ContentValues();
//         contentValues.put(DH_Card_No,record.CardNo);
//        contentValues.put(DH_Card_UsageCount,record.UsageCount);
//        contentValues.put(DH_Card_purchaseAmount,record.PurchaseAmount);
//        contentValues.put(DH_Card_remain,record.Remain);
//        contentValues.put(DH_Card_discountRate,record.DiscountRate);
//       // GlobalFunction.printText("tag","record"+" "+record.getUsageDate());
//        contentValues.put(DH_Card_Date,record.usageDate);
//        contentValues.put(DH_Card_DeviceNo,record.DeviceNo);
//        contentValues.put(DH_Card_Operator,record.Operator);
//        contentValues.put(DH_Card_ReportType,record.ReportType);
//        contentValues.put(DH_Card_ReportType,record.ReportType);
//        db.insert(DH_TABLE_NAME, null, contentValues);
//        db.close();
//
//        GlobalFunction.printText("tag","row:"+numberOfRows());
//    }

//        public int numberOfRows(){
//            SQLiteDatabase db = this.getReadableDatabase();
//            int numRows = (int) DatabaseUtils.queryNumEntries(db, DH_TABLE_NAME);
//
//            return numRows;
//        }

   void deleteItem(String itemNo){//删除商品列表的某个商品
//        SQLiteDatabase db=this.getWritableDatabase();
//
//
//     db.delete(MenuItemTB.DH_TABLE_NAME,MenuItemTB.item_ID+"=?",new String[]{itemNo});
//

    }


//    public ArrayList<CardRecord> getCardReport(String operator, int reportType) {
//        SQLiteDatabase db=this.getReadableDatabase();
//        Cursor res=db.rawQuery("select * from "+DH_TABLE_NAME+ " WHERE "+DH_Card_ReportType+" ="+ String.valueOf(reportType),null);
//        res.moveToFirst();
//        ArrayList<CardRecord> recordList=new ArrayList<>();
//
//        while (!res.isAfterLast()){
//            CardRecord record=new CardRecord(res.getString(res.getColumnIndex(DH_Card_No)))  ;
//            record.UsageCount=res.getInt(res.getColumnIndex(DH_Card_UsageCount));
//            record.PurchaseAmount=res.getInt(res.getColumnIndex(DH_Card_purchaseAmount));
//            record.Remain=res.getInt(res.getColumnIndex(DH_Card_remain));
//            record.DiscountRate=res.getString(res.getColumnIndex(DH_Card_discountRate));
//            record.usageDate=res.getString(res.getColumnIndex(DH_Card_Date));
//            record.DeviceNo=res.getString(res.getColumnIndex(DH_Card_DeviceNo));
//            record.Operator=res.getString(res.getColumnIndexOrThrow(DH_Card_Operator));
//            record.ReportType=res.getInt(res.getColumnIndex(DH_Card_ReportType));
//            record.cardName=res.getString(res.getColumnIndex(DH_Card_Name));
//
//
//            recordList.add(record);
//
//
//
//            res.moveToNext();
//
//        }
//        res.close();
//
//        return recordList;
//
//    }

//    public String getPurchaseTotalAmount(String date){
//       int total_price=0;
//        GlobalFunction.printTextByTag(date);
//        SQLiteDatabase db=this.getReadableDatabase();
//        String query="select sum("+PurchasedItemTB.item_totalPrice+")"+" from "+PurchasedItemTB.DH_TABLE_NAME+" where "
//                +PurchasedItemTB.item_purchDate+" = " + "\""+date+"\"";
//        Cursor res=db.rawQuery(query,null);
//
//
//        GlobalFunction.printTextByTag(query);
//        if (res.moveToFirst()){
//
//            total_price=res.getInt(0);
//
//        }
//       return String.valueOf(total_price);
//
//    }

//    public ArrayList<PurchasedItemTB.Item> sumUpPurchaseGoodAmount(String date, int paymodeType){
//        SQLiteDatabase db=this.getReadableDatabase();
//        String query="select sum("+PurchasedItemTB.item__amount+")"+" as \"Total\""+","+PurchasedItemTB.item_name+","+PurchasedItemTB.item_ID+","+PurchasedItemTB.item_SaleCost
//        +" from "+PurchasedItemTB.DH_TABLE_NAME +" where " +PurchasedItemTB.item_purchDate+" = " + "\""+date+"\"" +" and "+PurchasedItemTB.item_payMode+"="+ String.valueOf(paymodeType) +" GROUP BY "+"\""+PurchasedItemTB.item_name+"\"";
//
//        Cursor res=db.rawQuery(query,null);
//
//      ArrayList<PurchasedItemTB.Item> recordList=new ArrayList<>();
//
//
//        if (res.moveToFirst()){
//
//          GlobalFunction.printTextByTag("query success");
//
//
//            while (!res.isAfterLast()){
//
//                PurchasedItemTB.Item item=new PurchasedItemTB.Item(res.getString(res.getColumnIndex(PurchasedItemTB.item_ID)));
//                item.item_name=res.getString(res.getColumnIndex(PurchasedItemTB.item_name));
//                item.item_amount=res.getInt(res.getColumnIndex("Total"));
//                item.saleCost=res.getInt(res.getColumnIndex(PurchasedItemTB.item_SaleCost));
//
//                recordList.add(item);
//
//
//
//                res.moveToNext();
//
//            }
//
//        }else {
//            GlobalFunction.printTextByTag("query fail");
//        }
//        res.close();
//
//        return recordList;
//
//
//    }





//    ArrayList<PurchasedItemTB.Item> getPurchasedItemHistory() {
//        SQLiteDatabase db=this.getReadableDatabase();
//        Cursor res=db.rawQuery("select * from "+ PurchasedItemTB.DH_TABLE_NAME ,null);
//        res.moveToFirst();
//        ArrayList<PurchasedItemTB.Item> recordList=new ArrayList<>();
//
//        while (!res.isAfterLast()){
//
//            PurchasedItemTB.Item item=new PurchasedItemTB.Item(res.getString(res.getColumnIndex(PurchasedItemTB.item_ID)));
//            item.card_ID=res.getString(res.getColumnIndex(PurchasedItemTB.item_CardID));
//            item.item_TicketID=res.getString(res.getColumnIndex(PurchasedItemTB.item_TicketID));
//            item.item_name=res.getString(res.getColumnIndex(PurchasedItemTB.item_name));
//            item.item_amount=res.getInt(res.getColumnIndex(PurchasedItemTB.item__amount));
//            item.item_payMode=res.getInt(res.getColumnIndex(PurchasedItemTB.item_payMode));
//            item.saleCost=res.getInt(res.getColumnIndex(PurchasedItemTB.item_SaleCost));
//            item.item_purchDate=res.getString(res.getColumnIndex(PurchasedItemTB.item_purchDate));
//            recordList.add(item);
//
//
//
//            res.moveToNext();
//
//        }
//        res.close();
//
//        return recordList;
//
//    }

//    ArrayList<PurchasedItemTB.Item> getPurchasedItemHistoryBaseOnPurchaseType(Integer type) {
//        SQLiteDatabase db=this.getReadableDatabase();
//        Cursor res=db.rawQuery("select * from "+ PurchasedItemTB.DH_TABLE_NAME+" WHERE " + PurchasedItemTB.item_payMode+" ="+ String.valueOf(type) ,null);
//
//
//
//        res.moveToFirst();
//        ArrayList<PurchasedItemTB.Item> recordList=new ArrayList<>();
//
//        while (!res.isAfterLast()){
//
//            PurchasedItemTB.Item item=new PurchasedItemTB.Item(res.getString(res.getColumnIndex(PurchasedItemTB.item_ID)));
//            item.card_ID=res.getString(res.getColumnIndex(PurchasedItemTB.item_CardID));
//            item.item_TicketID=res.getString(res.getColumnIndex(PurchasedItemTB.item_TicketID));
//            item.item_name=res.getString(res.getColumnIndex(PurchasedItemTB.item_name));
//            item.item_amount=res.getInt(res.getColumnIndex(PurchasedItemTB.item__amount));
//            item.item_payMode=res.getInt(res.getColumnIndex(PurchasedItemTB.item_payMode));
//            item.saleCost=res.getInt(res.getColumnIndex(PurchasedItemTB.item_SaleCost));
//            item.item_purchDate=res.getString(res.getColumnIndex(PurchasedItemTB.item_purchDate));
//            recordList.add(item);
//
//
//
//            res.moveToNext();
//
//        }
//        res.close();
//
//        return recordList;
//
//    }


//      ArrayList<RefundGoodTB.Item> getRefundedItemList(PurchasedItemTB.Item purchaseItem) {
//        SQLiteDatabase db=this.getReadableDatabase();
//        Cursor res=db.query(RefundGoodTB.DH_TABLE_NAME,null,  RefundGoodTB.item_TicketID + " = ?" +" AND "+RefundGoodTB.item_ID+" = ?"+ " AND "+RefundGoodTB.item_payMode+
//                 " = ?", new String[]{purchaseItem.item_TicketID,purchaseItem.item_ID, String.valueOf(purchaseItem.item_payMode) },null,null,null);
//
//        res.moveToFirst();
//
//        ArrayList<RefundGoodTB.Item> recordList=new ArrayList<>();
//        while (!res.isAfterLast()){
//
////    GlobalFunction.printTextByTag("query "+purchaseItem.item_TicketID+" "+purchaseItem.item_ID);
//
//
//            RefundGoodTB.Item item=  new RefundGoodTB.Item(res.getString(res.getColumnIndex(RefundGoodTB.item_ID)));
//           // item.card_ID=res.getString(res.getColumnIndex(PurchasedItemTB.item_CardID));
//            item.item_TicketID=res.getString(res.getColumnIndex(RefundGoodTB.item_TicketID));
//            item.item_name=res.getString(res.getColumnIndex(RefundGoodTB.item_name));
//            item.item_amount=res.getInt(res.getColumnIndex(RefundGoodTB.item__amount));
//            item.item_payMode=res.getInt(res.getColumnIndex(RefundGoodTB.item_payMode));
//            item.saleCost=res.getInt(res.getColumnIndex(RefundGoodTB.item_SaleCost));
//            item.item_purchDate=res.getString(res.getColumnIndex(RefundGoodTB.item_purchDate));
//            item.item_refundDate=res.getString(res.getColumnIndex(RefundGoodTB.item_refundDate));
//
//            recordList.add(item);
//
//            res.moveToNext();
//
//        }
//
//        res.close();
//
//        return recordList;
//
//    }

//    ArrayList<RefundGoodTB.Item> getAllRefundedItemListBaseOnType(int type){
//        SQLiteDatabase db=this.getReadableDatabase();
//        Cursor res=db.rawQuery("select * from "+ RefundGoodTB.DH_TABLE_NAME+" WHERE " + RefundGoodTB.item_payMode+" ="+ String.valueOf(type) ,null);
//
//
//
//        res.moveToFirst();
//        ArrayList<RefundGoodTB.Item> recordList=new ArrayList<>();
//
//        while (!res.isAfterLast()){
//
//            RefundGoodTB.Item item=new RefundGoodTB.Item(res.getString(res.getColumnIndex(PurchasedItemTB.item_ID)));
//            item.card_ID=res.getString(res.getColumnIndex(PurchasedItemTB.item_CardID));
//            item.item_TicketID=res.getString(res.getColumnIndex(PurchasedItemTB.item_TicketID));
//            item.item_name=res.getString(res.getColumnIndex(PurchasedItemTB.item_name));
//            item.item_amount=res.getInt(res.getColumnIndex(PurchasedItemTB.item__amount));
//            item.item_payMode=res.getInt(res.getColumnIndex(PurchasedItemTB.item_payMode));
//            item.saleCost=res.getInt(res.getColumnIndex(PurchasedItemTB.item_SaleCost));
//            item.item_purchDate=res.getString(res.getColumnIndex(PurchasedItemTB.item_purchDate));
//            item.item_refundDate=res.getString(res.getColumnIndex(RefundGoodTB.item_refundDate));
//
//            recordList.add(item);
//
//
//
//            res.moveToNext();
//
//        }
//        res.close();
//
//
//    return recordList;
//
//    }

//   public int getCardReportRefundIndex(String cardID){
//        SQLiteDatabase db=this.getReadableDatabase();
//        Cursor res=db.rawQuery("select * from "+DH_TABLE_NAME+ " WHERE "+DH_Card_No+" = "+cardID,null);
//        res.moveToFirst();
//
//        CardRecord record=null;
//
//        while (!res.isAfterLast()){
//            record=new CardRecord(res.getString(res.getColumnIndex(DH_Card_No)))  ;
//            record.UsageCount=res.getInt(res.getColumnIndex(DH_Card_UsageCount));
//            record.PurchaseAmount=res.getInt(res.getColumnIndex(DH_Card_purchaseAmount));
//            record.Remain=res.getInt(res.getColumnIndex(DH_Card_remain));
//            record.DiscountRate=res.getString(res.getColumnIndex(DH_Card_discountRate));
//            record.usageDate=res.getString(res.getColumnIndex(DH_Card_Date));
//            record.DeviceNo=res.getString(res.getColumnIndex(DH_Card_DeviceNo));
//            record.Operator=res.getString(res.getColumnIndexOrThrow(DH_Card_Operator));
//            record.ReportType=res.getInt(res.getColumnIndex(DH_Card_ReportType));
//            record.cardName=res.getString(res.getColumnIndex(DH_Card_Name));
//            record.refundIndex=res.getInt(res.getColumnIndex(DH_Card_RefundIndex));
//
//
//
//
//
//            res.moveToNext();
//
//        }
//        res.close();
//
//        return record.refundIndex;
//
//
//
//    }

// public    void updateCardRefundIndex(CardRecord cardRecord){
//         SQLiteDatabase db=this.getReadableDatabase();
//       cardRecord.setRefundIndex(1);//表示退过款
//
//    String query="UPDATE "+DH_TABLE_NAME+ " SET "+ DH_Card_RefundIndex + "=1"+" WHERE "+DH_Card_No+"="+cardRecord.getCardNo();
//    db.execSQL(query);
//db.close();
//GlobalFunction.printTextByTag(cardRecord.getCardNo());
//    }



//    ArrayList<Goods> getAllMenuItem(){//获取商品列表所有商品
//
//        ArrayList<Goods> itemArrayList=new ArrayList<>();
//
//        SQLiteDatabase db=this.getReadableDatabase();
//        Cursor res=db.rawQuery("select * from "+ MenuItemTB.DH_TABLE_NAME ,null);
//        res.moveToFirst();
//
//        while (!res.isAfterLast()){
//
//              Goods item=new     Goods();
//            item.setItemNo(res.getString(res.getColumnIndex(MenuItemTB.item_ID)));
//            item.setItemName(res.getString(res.getColumnIndex(MenuItemTB.item_ID)));
//            item.setAmount(res.getInt(res.getColumnIndex(MenuItemTB.item_amount)));
//            item.setRetailPrice(res.getInt(res.getColumnIndex(MenuItemTB.item_retailPrice)));
//
//
//             itemArrayList.add(item);
//
//        res.moveToNext();
//
//        }
//        res.close();
//
//
//        return itemArrayList;
//
//    }


}
